package com.qiche.mock


import com.qiche.common.SparkBase
import com.qiche.model.{OdsClassInfo}
import org.apache.spark.sql.SparkSession

object OdsClassInfoMock extends SparkBase {

  def execute(spark: SparkSession): Unit = {
    import spark.implicits._

    val base = spark.read.textFile("E:\\sihuo\\PingTai\\src\\zhuanye.txt")
    base.map(x => {
      val array = x.split(",")

      new OdsClassInfo(
        array(1).trim,
        array(2).trim,
        array(3).trim,
        array(0).trim
      )
    }).toDF().createTempView("ods_class_info_view")

    spark.sql(
      s"""insert into table pingtai.ods_class_info select * from ods_class_info_view""".stripMargin)
  }


  def main(args: Array[String]): Unit = {
    System.setProperty("HADOOP_USER_NAME", "hadoop")
    System.setProperty("HIVE_USER_NAME", "hadoop")
    val spark = getContextLocal(this.getClass.getName.split('.').last)
    execute(spark)
    spark.stop()
  }
}



